package com.cci.kangdao.controller;

import com.cci.kangdao.service.BusinessService;
import com.cci.kangdao.service.CSUService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

//CSU相关
@Controller
public class CSUController {


	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private CSUService csuService;


	//通过esn获取用户相关信息
	@RequestMapping("/getUserInfoByESNCSU.aspx")
	public ModelAndView getUserInfoByESNCSU(HttpServletRequest request,
											 HttpServletResponse response,@RequestBody String contentJson) throws Exception {
		try{
			log.info("接口传参为"+contentJson);
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			map.put("contentJson",contentJson);
			return csuService.getUserInfoByESNCSU(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//手机发送验证码
	@RequestMapping("/sendVerifyCodeByPhoneCSU.aspx")
	public ModelAndView sendVerifyCodeByPhoneCSU(HttpServletRequest request,
											HttpServletResponse response,@RequestBody String contentJson) throws Exception {
		try{
			log.info("接口传参为"+contentJson);
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			map.put("contentJson",contentJson);
			return csuService.sendVerifyCodeByPhoneCSU(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//校验手机号和验证码是否有效
	@RequestMapping("/checkVerifyCodePhoneStatusCSU.aspx")
	public ModelAndView checkVerifyCodePhoneStatusCSU(HttpServletRequest request,
											HttpServletResponse response,@RequestBody String contentJson) throws Exception {
		try{
			log.info("接口传参为"+contentJson);
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			map.put("contentJson",contentJson);
			return csuService.checkVerifyCodePhoneStatusCSU(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
}
